﻿using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Messaging;
using Microsoft.Extensions.DependencyInjection;
using Model.Core.Services;
using System.IO;

namespace RobotPratolSolution.ViewModels
{
    public class MainWindowViewModel : ObservableObject,IRecipient<string>
    {
        private string _windowTitle= "意美特机器人管理客户端";
        public string WindowTitle
        {
            get => _windowTitle;
            set
            {
                _windowTitle = value;
                OnPropertyChanged();
            }
        }

        public MainWindowViewModel()
        {
            WeakReferenceMessenger.Default.Register<string>(this);
            LoadRobotBaseInfo();
        }

        private void LoadRobotBaseInfo()
        {
            try
            {
                var  LocalRobotInfo = App.ServiceProvider.GetService<LocalRobotInfo>();
                WindowTitle = "意美特-"+LocalRobotInfo.RobotName + "-" + LocalRobotInfo.RobotId;
            }
            catch (Exception ex)
            {
                WindowTitle = "配置加载失败";
                // 这里可以添加日志记录
            }
        }

        public void Receive(string message)
        {
            Console.WriteLine(message);
            LoadRobotBaseInfo();
        }
    }

}
